#!/bin/python3
# -*- coding:utf-8 -*-
"""
    [模块名]
    By :陈狍子 e4ting@qq.com 2024-12-07 18:53:24
"""
import sys,os
from pdb import set_trace as strace
from traceback  import format_exc as dumpstack
from e4ting import util,log

from e4ting.cache import UUIDCache

class UUID():
    def __init__(self, info=None):
        self.head = "E4"
        self.info = info

    def _crc_(self, info=None):
        payload = info or self.info
        assert bool(payload),"载体不能为空"
        ret  = util.crc(str(info).lower())
        return self.int2str(ret, need=2)

    def int2str(self, number, need=4):
        data = util.baseconvert(number, 10, 36)
        return data[-need:].zfill(need)

    def get(self):
        return self.calc(uuid=self.info)

    @UUIDCache.cache
    def calc(self, uuid=""):
        """生成客户端唯一ID"""
        rand = UUIDCache._id
        fill_info = self._crc_(self.info)
        return "{head}{crc}{rand}".format(head=self.head, crc=fill_info, rand=self.int2str(rand))

if __name__ == '__main__':
    for i in range(110):
        uid = UUID(f"test {i}")
        # strace()
        ret = uid.get()
        log.info(ret)




